<!--
 * @Autor: Haiting Zhao
 * @Date: 2021-12-08 10:42:58
 * @LastEditors: Haiting Zhao
 * @LastEditTime: 2021-12-19 12:59:38
 * @Description: file content
 * @FilePath: \Management-of-Scientific-Research-in-Universities-Front\src\views\kyproject\Apply.vue
-->
<template>
  <div class="inde">
    <div class="mbx">
      <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom:10px">
        <el-breadcrumb-item :to="{ name:'WorkPlace' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>科研项目</el-breadcrumb-item>
        <el-breadcrumb-item>科研项目在线申报</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="f">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="项目logo" prop="logo">
          <div>
            <el-upload
              ref="logoupload"
              :action="uploadUrl()"
              list-type="picture-card"
              :auto-upload="false"
              :limit="1"
              name="logo"
              :data="upData"
              :on-remove="handleRemove"
              :before-upload="beforeAvatarUpload"
              :on-change="beforeupload111"
              :on-error="uploadFalse"
              :on-success="uploadSuccess"
            >
              <i slot="default" class="el-icon-plus" />
              <div slot="logofile" slot-scope="{file}">
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="logofile.url"
                  alt=""
                >
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-preview"
                    @click="handlePictureCardPreview(file)"
                  >
                    <i class="el-icon-zoom-in" />
                  </span>
                  <span
                    v-if="!disabled"
                    class="el-upload-list__item-delete"
                  >
                    <i class="el-icon-delete" />
                  </span>
                </span>
              </div>
            </el-upload>
          </div>
        </el-form-item>

        <el-form-item label="项目名称" prop="projectName">
          <el-col :span="11">
            <el-input v-model="ruleForm.projectName" type="text" placeholder="请输入项目名称" />
          </el-col>
          <el-col :span="11">
            <el-form-item label="负责人姓名" prop="leaderId">
              <!-- {{ ruleForm.leaderId }} -->
              <el-input v-model="userinformation.userRealname" readonly type="text" placeholder="请输入项目负责人姓名" />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="所在单位" prop="department_id">
          <el-col :span="11">
            <!-- <el-form-item label="所在单位" prop="department_id"> -->
            <el-select v-model="ruleForm.department_id" placeholder="请选择所在单位" @focus="getdepartmentlist()">
              <el-option
                v-for="(item,index) in departmentList"
                :key="index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <!-- </el-form-item> -->
          </el-col>
          <el-col :span="11">
            <el-form-item label="成果归属" prop="aod_id">
              <el-select v-model="ruleForm.aod_id" placeholder="请选择成果归属单位" @focus="getdepartmentlist()">
                <el-option
                  v-for="(item,index) in departmentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="学科门类" prop="sc_id">
          <el-col :span="11">
            <el-select v-model="ruleForm.sc_id" placeholder="请选择学科门类" @focus="getsclist()">
              <el-option
                v-for="(item,index) in scList"
                :key="index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-col>
          <el-col :span="11">
            <el-form-item label="一级学科" prop="subject_id">
              <el-select v-model="ruleForm.subject_id" placeholder="请选择一级学科" @focus="getsubjectlist()">
                <el-option
                  v-for="(item,index) in subjectList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="项目性质" prop="nature_id">
          <el-col :span="11">
            <el-form-item>
              <el-select v-model="ruleForm.nature_id" placeholder="请选择项目性质" @focus="getnaturelist()">
                <el-option
                  v-for="(item,index) in natureList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="项目级别" prop="level_id">
              <el-select v-model="ruleForm.level_id" placeholder="请选择项目级别" @focus="getlevellist()">
                <el-option
                  v-for="(item,index) in levelList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="成果形式" prop="at_id">
          <el-col :span="11">
            <el-form-item>
              <el-select v-model="ruleForm.at_id" placeholder="请选择成果形式" @focus="getatlist()">
                <el-option
                  v-for="item in atList"
                  :key="item.id"
                  :label="item.atName"
                  :value="item.atId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="结题形式" prop="ct_id">
              <el-select v-model="ruleForm.ct_id" placeholder="请选择结题形式" @focus="getctlist()">
                <el-option
                  v-for="(item,index) in ctList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="计划时间" required>
          <el-col :span="11">
            <el-form-item prop="plan_time">
              <el-date-picker
                v-model="ruleForm.plan_time"
                type="date"
                placeholder="选择日期"
                style="width: 100%;"
                :picker-options="pickerOptions0"
                time-zone="local"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="合同经费" prop="outlay">
              <el-input v-model.number="ruleForm.outlay" type="text" placeholder="请输入合同经费" />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="项目概述" prop="introduction">
          <el-col :span="22">
            <el-input v-model="ruleForm.introduction" type="textarea" :autosize="{ minRows: 2, maxRows: 10}" maxlength="500" show-word-limit />
          </el-col>
        </el-form-item>
        <el-form-item label="团队成员">
          <el-button type="primary" style="margin-bottom:10px" icon="el-icon-plus" @click="AddProjectMember = true">
            添加成员
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-col :span="22">
            <el-table :data="addlist" border stripe>
              <el-table-column type="index" label="#" />
              <el-table-column label="成员姓名" prop="userRealname" />
              <el-table-column label="成员电话" prop="userMobile" />
              <el-table-column label="成员邮箱" prop="userEmail" />
              <el-table-column label="成员学工号" prop="userNumber" />
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    icon="el-icon-thumb"
                    size="mini"
                    @click="deleteteamuser(scope.row,scope.$index)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-form-item>

        <el-form-item label="上传附件" prop="enclosureform">
          <el-upload
            ref="upload"
            class="upload-demo"
            :action="uploadUrl2()"
            :on-preview="handlePreview2"
            :on-remove="handleRemove2"
            :data="upData2"
            :on-error="uploadFalse2"
            :on-success="uploadSuccess2"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload2"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <div slot="tip" class="el-upload__tip">请上传附件！</div>
          </el-upload>
        </el-form-item>

        <el-form-item>
          <el-button v-preventReClick="3000" type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>

        <!-- 添加团队成员对话框 -->
        <el-dialog
          title="添加团队成员"
          :visible.sync="AddProjectMember"
          width="50%"
          @close="AddProjectMemberClosed"
        >
          <el-form
            ref="AddProjectMemberFormRef"
            :model="AddProjectMemberForm"
            :rules="AddProjectMemberFormRules"
            label-width="100px"
          >
            <el-form-item prop="">
              <el-col style="width: 60%;">
                <el-input v-model="searchusernumber" placeholder="请输入成员学工号进行查询">
                  <el-button slot="append" type="primary" @click="searchnumber">搜 索</el-button>
                </el-input>
              </el-col>
            </el-form-item>
            <el-table :data="[userList]" border stripe>
              <el-table-column type="index" label="#" />
              <el-table-column label="成员姓名" prop="userRealname" />
              <el-table-column label="成员电话" prop="userMobile" />
              <el-table-column label="成员邮箱" prop="userEmail" />
              <el-table-column label="成员学工号" prop="userNumber" />
            </el-table>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="AddProjectMember = false">取 消</el-button>
            <el-button type="primary" @click="AddTeamMember">确 定</el-button>
          </span>
        </el-dialog>
      </el-form>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import crypto from '../../crypto/crypto'
export default {
  name: 'Apply',
  data() {
    return {
      logofile: '', // logo文件
      utc: '', // 开始时间
      utc1: '', // 计划完成时间
      departmentList: [], // 数据字典
      scList: [],
      subjectList: [],
      natureList: [],
      levelList: [],
      atList: [],
      ctList: [],
      searchusernumber: '', // 搜索成员框数据
      userList: [], // 搜索到的成员信息
      userinformation: '', // 当前人员真实信息
      ruleForm: { // 表单
        logo: '',
        projectName: '',
        projectId: '',
        leaderId: this.$store.getters.getuserId,
        department_id: '',
        aod_id: '',
        sc_id: '',
        subject_id: '',
        nature_id: '',
        level_id: '',
        at_id: '',
        ct_id: '',
        plan_time: '',
        outlay: '',
        introduction: ''
      },
      form: { // logo上传表单
        logo: '',
        projectId: ''
      },
      enclosureform: { // 附件上传表单
        projectId: '',
        atId: '0',
        categoryId: '0',
        status: '1',
        file: ''
      },
      addlist: [], // 成员列表 实现前端增删 最后上传
      disabled: false,
      //   添加用户对话框
      AddProjectMember: false,
      // 添加角色表单
      AddProjectMemberForm: {},
      //   添加角色表单验证
      AddProjectMemberFormRules: {
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ]
      },
      rules: {
        projectName: [
          { required: true, message: '请输入项目名称', trigger: 'blur' },
          { min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur' }
        ],
        department_id: [
          { required: true, message: '请选择所在单位', trigger: 'change' }
        ],
        aod_id: [
          { required: true, message: '请选择成果归属单位', trigger: 'change' }
        ],
        sc_id: [
          { required: true, message: '请选择学科门类', trigger: 'change' }
        ],
        subject_id: [
          { required: true, message: '请选择一级学科', trigger: 'change' }
        ],
        nature_id: [
          { required: true, message: '请选择项目性质', trigger: 'change' }
        ],
        level_id: [
          { required: true, message: '请选择项目级别', trigger: 'change' }
        ],
        at_id: [
          { required: true, message: '请选择项目形式', trigger: 'change' }
        ],
        ct_id: [
          { required: true, message: '请选择结题形式', trigger: 'change' }
        ],
        outlay: [
          { required: true, message: '请选择合同经费', trigger: 'blur' },
          { pattern: /^[1-9]\d*$/, message: '请输入合法数字', trigger: 'blur' }
        ],
        leaderId: [
          { required: true }
        ],
        plan_time: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        introduction: [
          { required: true, message: '请填写项目概述', trigger: 'blur' }
        ]
      },
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7 // 如果没有后面的-8.64e7就是不可以选择今天的
        }
      }
    }
  },
  computed: {
    // 这里定义上传文件时携带的参数，即表单数据
    upData: function() {
      return this.form
    },
    upData2: function() {
      return this.enclosureform
    }
  },
  created() {
    this.getproductid()
    this.getleader()
  },
  methods: {

    /**
     * @description: 获取项目id
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    getproductid() {
      axios.get('/project/advance')
        .then(res => {
          this.ruleForm.projectId = res.data
          this.form.projectId = res.data.data
          this.enclosureform.projectId = res.data.data
          // console.log(this)
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 获取创建人真实姓名
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    getleader() {
      axios.get('/user/')
        .then((res) => {
          this.userinformation = res.data.data
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 获取各种数据字典
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    getdepartmentlist() {
      this.departmentList = JSON.parse(this.$store.getters.getdepartment)
      // console.log('根据id获取对应name', this.departmentList[2].name)
      this.departmentList = this.departmentList.filter(function(ele) { return ele !== null })
      // console.log('获取整个列表及id', this.departmentList)
    },
    getsclist() {
      this.scList = JSON.parse(this.$store.getters.getsc).filter(function(ele) { return ele !== null })
    },
    getsubjectlist() {
      this.subjectList = JSON.parse(this.$store.getters.getsubject).filter(function(ele) { return ele !== null })
    },
    getnaturelist() {
      this.natureList = JSON.parse(this.$store.getters.getnature).filter(function(ele) { return ele !== null })
    },
    getlevellist() {
      this.levelList = JSON.parse(this.$store.getters.getlevel).filter(function(ele) { return ele !== null })
    },
    getatlist() {
      axios.get('/dictionary/searchAll/achievementType')
        .then((response) => {
          var allist = response.data.data
          for (let index = 0; index < allist.length; index++) {
            if (allist[index].atId === 4) {
              delete allist[index]
            }
          }
          allist.length = allist.length - 1
          this.atList = allist
          // console.log(this.atList)
        })
        .catch(error => {
          console.log(error)
        })
    },
    getctlist() {
      this.ctList = JSON.parse(this.$store.getters.getct).filter(function(ele) { return ele !== null })
    },

    /**
     * @description: 添加团队成员对话框的关闭
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    AddProjectMemberClosed() {
      this.$refs.AddProjectMemberFormRef.resetFields()
    },

    /**
     * @description: 根据编号搜索成员
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    searchnumber() {
      axios.get('/user/searchByUserNumber', { params: { userNumber: this.searchusernumber }})
        .then(res => {
          if (res.data.code === 417) {
            this.$message({
              message: res.data.msg,
              type: 'error'
            })
            return
          }
          this.userList = res.data.data
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 将团队成员添加到addlist里面，展示在页面
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    AddTeamMember() {
      var userinf = { projectId: this.form.projectId, userId: this.userList.userId, teamRole: '成员', userRealname: this.userList.userRealname, userMobile: this.userList.userMobile, userEmail: this.userList.userEmail, userNumber: this.userList.userNumber }
      var iscunzai = 0
      if (this.addlist.length >= 1) { // 如果addlist里面有东西 在循环判断
        for (var i = 0; i < this.addlist.length; i++) { // 遍历add list
          if (userinf.userId === this.addlist[i].userId) { // 如果遍历到的userid等于要添加的userid
            iscunzai = 1 // 如果已经存在 则标记为1
            this.$message({
              message: '该用户已存在',
              type: 'error'
            })
          }
        }
        // for循环结束后 判断标志是否为0，如果为0，说明不存在 则添加到add list
        if (iscunzai === 0) {
          this.addlist.push(userinf) // 遍历完后 如果没有退出 那么添加成员
          // console.log(this.addlist)
        }
        // 关闭对话框
        this.AddProjectMember = false
      } else { // add list为空 直接添加
        this.addlist.push(userinf)
        this.AddProjectMember = false
        // console.log(this.addlist)
      }
    },

    /**
     * @description: 从addlist里面删除某个成员
     * @param {*} row
     * @param {*} index
     * @return {*}
     * @author: Haiting Zhao
     */
    deleteteamuser(row, index) {
      // console.log(row)
      // console.log(index)
      this.$confirm('将删除该成员, 是否继续?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.addlist.splice(index, 1)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    /**
     * @description: 添加团队成员 最后提交调用此函数
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    InsertTeamMember() {
      if (this.addlist.length !== 0) {
        axios.post('/projectTeam/insert', {
          teamList: this.addlist
        })
          .then((res) => {
            if (res.data.code === 200) {
              this.$message.success('成员添加成功')
              this.AddProjectMember = false
            } else {
              this.$message.error('成员添加失败')
            }
          })
          .catch(err => {
            console.error(err)
          })
      }
    },

    /**
     * @description: logo on-change
     * @param {*} file
     * @param {*} fileList
     * @return {*}
     * @author: Haiting Zhao
     */
    beforeupload111(file, fileList) {
      this.logofile = file // 此时的file已经是上传之后返回的信息了 // 这个居然是logo文件上传成功后才执行
    },

    /**
     * @description: logo移除文件
     * @param {*} file
     * @return {*}
     * @author: Haiting Zhao
     */
    handleRemove(file) {
      // console.log(file) // 本来是写来移除的 但是.......好像没有内容也可以移除
      // this.logofile = ''
      // console.log(fileList.length)
      // fileList.length = fileList.length - 1
      // console.log(fileList.length)
      // this.hideUpload = fileList.length >= this.limitcount
    },
    /**
     * @description: 上传logo的接口
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadUrl: function() {
      return '/api/projectFile/updateLogo' // 上传logo接口
      // return ''
    },

    /**
     * @description: 上传前对文件的大小和类型的判断
     * @param {*} file
     * @return {*}
     * @author: Haiting Zhao
     */
    beforeAvatarUpload(file) {
      // console.log(file)
      this.form.logo = file.name
      const extension = file.name.split('.')[1] === 'png'
      const extension2 = file.name.split('.')[1] === 'jpg'
      const extension3 = file.name.split('.')[1] === 'jpeg'
      this.form.logo = file
      if (!extension && !extension2 && !extension3) {
        this.$message({
          message: '上传文件只能是 png、jpg、jpge 格式!',
          type: 'error'
        })
      }
      return extension || extension2 || extension3
    },

    /**
     * @description: 上传logo
     * @param {*} form
     * @return {*}
     * @author: Haiting Zhao
     */
    submitUpload(form) { // 提交表单时调用触发
      this.$refs.logoupload.submit()
    },

    /**
     * @description: logo文件上传成功触发
     * @param {*} response
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadSuccess(response) {
      // console.log(response)
      if (response.code === 200) {
        this.$message({
          message: 'logo导入成功,请稍后',
          type: 'success'
        })
        // this.submitUpload2() // 调用上传附件
        // this.InsertTeamMember() // 调用插入成员
        this.submitformdata()
        // this.$router.push('/' + crypto.set('2'))
      } else {
        this.$message({
          message: 'logo导入失败，请稍后重试',
          type: 'error'
        })
      }
    },

    /**
     * @description: 文件上传失败触发
     * @param {*} response
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadFalse(response) {
      // console.log(response)
      this.$message({
        message: '文件上传失败！',
        type: 'error'
      })
    },

    /**
     * @description: 移除文件
     * @param {*} file
     * @param {*} fileList
     * @return {*}
     * @author: Haiting Zhao
     */
    handleRemove2(file, fileList) {
      console.log(file, fileList)
    },

    /**
     * @description: 预览
     * @param {*} file
     * @return {*}
     * @author: Haiting Zhao
     */
    handlePreview2(file) {
      console.log(file)
    },

    /**
     * @description: 上传附件接口
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadUrl2: function() {
      return '/api/projectFile/updateFile' // 上传附件接口
    },

    /**
     * @description: 上传前对附件文件的大小和类型的判断
     * @param {*} file
     * @return {*}
     * @author: Haiting Zhao
     */
    beforeAvatarUpload2(file) {
      this.enclosureform.file = file.name
      this.enclosureform.file = file
      // console.log(this.enclosureform.file)
      return 1
    },

    /**
     * @description: 上传附件
     * @param {*} enclosureform
     * @return {*}
     * @author: Haiting Zhao
     */
    submitUpload2(enclosureform) {
      this.$refs.upload.submit() // 提交表单时调用触发
    },

    /**
     * @description: 附件文件上传成功触发
     * @param {*} response
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadSuccess2(response) {
      // console.log(response)
      if (response.code === 200) {
        this.$message({
          message: '附件导入成功',
          type: 'success'
        })
        // this.submitformdata()
      } else {
        this.$message({
          message: '附件导入失败，请稍后重试',
          type: 'error'
        })
      }
    },

    /**
     * @description: 附件上传失败触发
     * @param {*} response
     * @return {*}
     * @author: Haiting Zhao
     */
    uploadFalse2(response) {
      // console.log(response)
      this.$message({
        message: '附件上传失败！',
        type: 'error'
      })
    },

    /**
     * @description: 时间格式生成
     * @param {*} t
     * @return {*}
     * @author: Haiting Zhao
     */
    formatDate(t) {
      return t <= 9 ? '0' + t : t
    },

    /**
     * @description: 生成utc时间
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    gettimes() {
      var date = new Date()
      var year = date.getFullYear()
      var month = this.formatDate(date.getMonth() + 1)
      var day = this.formatDate(date.getDate())
      var hour = this.formatDate(date.getHours())
      var minute = this.formatDate(date.getMinutes())
      var second = this.formatDate(date.getSeconds())
      var utc = year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + '.000Z'
      // console.log(utc) // 创建时间 即当前时间
      this.utc = utc
      var plantime = this.ruleForm.plan_time
      // console.log(plantime)
      var year1 = plantime.getFullYear()
      var month1 = this.formatDate(plantime.getMonth() + 1)
      var day1 = this.formatDate(plantime.getDate())
      var utc1 = year1 + '-' + month1 + '-' + day1 + 'T' + hour + ':' + minute + ':' + second + '.000Z'
      // console.log(utc1) // 计划完成时间 即选择框中日期加上当前时分秒
      this.utc1 = utc1
    },

    /**
     * @description: 表单上传
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    submitformdata() {
      axios.post('/project/apply', { // 上传表单
        aodId: this.ruleForm.aod_id,
        atId: this.ruleForm.at_id,
        completeTime: '2021-11-17T16:00:00.000Z', // 完成时间
        ctId: this.ruleForm.ct_id,
        departmentId: this.ruleForm.department_id,
        introduction: this.ruleForm.introduction,
        leaderId: this.ruleForm.leaderId,
        levelId: this.ruleForm.level_id,
        natureId: this.ruleForm.nature_id,
        outlay: this.ruleForm.outlay,
        planTime: this.utc1, // 计划完成时间
        projectId: this.ruleForm.projectId.data,
        projectName: this.ruleForm.projectName,
        scId: this.ruleForm.sc_id,
        sdId: this.ruleForm.department_id,
        startTime: this.utc, // 开始时间
        subjectId: this.ruleForm.subject_id
      })
        .then((res) => {
          if (res.data.code === 200) {
            this.$message.success('数据提交成功！请稍后')
            // this.submitUpload()
            // this.$router.push('/' + crypto.set('2'))
            this.submitUpload2() // 调用上传附件
            this.InsertTeamMember() // 调用插入成员
            this.$router.push('/' + crypto.set('2'))
          } else {
            this.$message.error('项目申请失败！请刷新页面后重试')
          }
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 提交表单创建项目
     * @param {*} formName
     * @return {*}
     * @author: Haiting Zhao
     */
    submitForm(formName) {
      var files = this.$refs.logoupload.uploadFiles
      if (files.length === 0) {
        this.$message({
          message: '您还未选择项目logo',
          type: 'error'
        })
        return
      }
      var files1 = this.$refs.upload.uploadFiles
      if (files1.length === 0) {
        this.$message({
          message: '您还未选择附件材料',
          type: 'error'
        })
        return
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.gettimes() // 生成当前世家，修改计划完成时间
          this.submitUpload() // 上传logo文件
          // this.InsertTeamMember() // 上传成员列表
          // this.submitformdata() // 上传表单
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },

    /**
     * @description: 清空表单
     * @param {*} formName
     * @return {*}
     * @author: Haiting Zhao
     */
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }

  }
}

</script>
<style lang="less">
.inde{
  width: 100%;
  height: 100%;
}
.mbx{
  margin-top: 10px;
  margin-left: 10px;
}
.disabled .el-upload--picture-card {
  display: none !important;
}
.hide .el-upload--picture-card {
  display: none;
}
// .f{
//   // position:absolute;                          //样式问题
// }
.imglogo{
  width: 30px;
  height: 30px;

}
</style>
